package com.zsrt.java.day20161227.hb.demo04;

import org.junit.Test;

public class Demo04 {
	
	@Test
  
	public void doudizhu(){
		//构造一副牌
		String[] pai01=new String[]{"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K","黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K","梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K","方片A","方片2","方片3","方片4","方片5","方片6","方片7","方片8","方片9","方片10","方片J","方片Q","方片K","小猫","大猫"};
		String pai02[];
		pai02=new String[17];
		String pai03[];
		pai03=new String[17];
		String pai04[];
		pai04=new String[17];
		 
		//输出第1个人的手牌
		System.out.println("第1个人的手牌为：");
		for(int i=0;i<17;i++){
			
			double a=Math.random();
			double b=a*pai01.length;
			int index=(int)Math.floor(b);
			pai02[i]=pai01[index];
			pai01=del(pai01,pai01[index]);
			System.out.print(pai02[i]+"\t");
			
		}
		System.out.println();
		
		//输出第2个人的手牌
		System.out.println("第2个人的手牌为：");
		for(int i=0;i<17;i++){
			
			double a=Math.random();
			double b=a*pai01.length;
			int index=(int)Math.floor(b);
			pai03[i]=pai01[index];
			pai01=del(pai01,pai01[index]);
			System.out.print(pai03[i]+"\t");
			 
		}
		System.out.println();
		
		//输出第3个人的手牌
		System.out.println("第3个人的手牌为：");
		for(int i=0;i<17;i++){
			
			double a=Math.random();
			double b=a*pai01.length;
			int index=(int)Math.floor(b);
			pai04[i]=pai01[index];
			pai01=del(pai01,pai01[index]);
			System.out.print(pai04[i]+"\t");
			
		}
		System.out.println();
		
		//输出底牌
		System.out.println("底牌为：");
		for(int i=0;i<3;i++){
			
			System.out.print(pai01[i]+"\t");
			
		}
		 
	}
	
	/**
	 * 构造一个删除String类型数组元素的方法，返回值为一个删除之后的新数组
	 * 参数有：被改数组和被改元素
	 */
	
	public static String[] del(String[] oldarray,String del){
		
		String newarray[];
		newarray=new String[oldarray.length-1];
		int xb=0;
		for(int index01=0;index01<oldarray.length;index01++){
			
			if(oldarray[index01]==del){
				
				xb=index01;
				break;
				
			}
		}
		for(int index02=0;index02<xb;index02++){
			
			newarray[index02]=oldarray[index02];
			
		}
		for(int index03=xb;index03<oldarray.length-1;index03++){
			
			newarray[index03]=oldarray[index03+1];
			
		}
		return newarray;
		 
	}

}
